#include<vector>
#include<algorithm>
struct TreeNode
{
    int val;
    TreeNode* left;
    TreeNode* right;

    TreeNode() : val(0), left(nullptr), right(nullptr)
    {
    }

    TreeNode(int x) : val(x), left(nullptr), right(nullptr)
    {
    }

    TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right)
    {
    }
};
class Solution {
public:
    int yes = 0;
    int no = 0;
    int rob(TreeNode* root) {
        r(root);
        return std::max(yes,no);
    }
    void r(TreeNode* root)
    {
        if (root == nullptr)
        {
            yes = 0;
            no = 0;
            return;
        }
        int y = root->val;
        int  n = 0;
        r(root->left);
        y+=no;
        n += std::max(yes,no);
        r(root->right);
        y+= no;
        n += std::max(yes,no);
        yes = y;
        no = n;
        
    }
};

